/**
 * 版权所有 2009-2015 中国中医科学院中医药信息研究所 何前锋 frontpeak@yahoo.com.cn
 **/
package cn.ac.cintcm.sh.domain;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.Map.Entry;

public class Wei {
    public static final String ROOT = "味";
    private static HashMap<String, Float> nameValue;
    private static HashMap<String, String> parent;
    private static String[] list = {"辛", "甘", "苦", "酸", "涩", "咸", "淡"};
    
    static {
        float value;
        nameValue = new HashMap<String, Float>();
        parent = new HashMap<String, String>();
        for (String s : list) {
            value = 0.63f;
            nameValue.put("微" + s, value);
            value = 1f;
            nameValue.put(s, value);
            value = 1.6f;
            nameValue.put("大" + s, value);
            
            nameValue.put("总" + s, 1.0f);
            
            parent.put("总" + s, ROOT);
            parent.put("微" + s, "总" + s);
            parent.put(s, "总" + s);
            parent.put("大" + s, "总" + s);
        }
    }

    public static float getValue(String wei) {
        Float value = nameValue.get(wei);
        if (value == null) {
            value = 0f;
            System.out.println(wei + " 找不到味");
        }
        return value;
    }
    
    public static String getParent(String wei) {
        return parent.get(wei);
    }
    
    public static List<String> getChildren(String wei) {
        List<String> list = new ArrayList<String>();
        Set<Entry<String, String>> entries = parent.entrySet();
        for( Entry<String, String> entry : entries) {
            if (entry.getValue().equals(wei)) {
                list.add(entry.getKey());
            }
        }
        return list;
    }

}